<template>
  <div>
    <mt-header title="后台登录管理系统">
      <router-link to="/" slot="left">
        <!-- <i class="mintui mintui-back lic-d"></i> -->
      </router-link>
    </mt-header>
    <div class="search">
      <input type="text" class="bd" placeholder="请输入用户名" v-model="agentId">
      <input type="password" class="bd" placeholder="请输入密码" v-model="kpassword">
      <button class="btn" @touchend="Login">登录</button>
    </div>
  </div>
</template>

<script>
  import {
    login
  } from "../api/api";
  import {
    Toast
  } from 'mint-ui';
  export default {
    data() {
      return {
        agentId: "",
        kpassword: ""
      };
    },
    methods: {
      Login() { //登录请求
      sessionStorage.setItem("token", this.agentId);
        if (this.agentId != "") {
              let loginData = {
                agentId: this.agentId,
                kpassword: this.kpassword
          };
          login(loginData.agentId, loginData.kpassword).then(res => {
              console.log(res.data)
            if (res.data.code == 0) {
              // sessionStorage.setItem("token", res.data.data); //localStorage
              sessionStorage.setItem("token",res.data.sessionId);
              if (res.data.data == "admin") {
                this.$router.push("/");
                Toast('登录成功');
                
              } else {
                this.$router.push("/homes");
                Toast('登录成功');
              }
            } else {
                  Toast('用户名或密码错误');
            }
          });
        }
      }
    }
  };
</script>


<style lang="less" scoped>
  a {
    text-decoration: none;
  }
  .lic-d {
    font-size: 50px;
  }
  .mint-header {
    background: -webkit-linear-gradient(left, #6180f4, #79cbfa);
    font-size: 36px;
    height: 80px;
  }
  .search {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 54px;
    margin-bottom: 40px;
    margin-top: 150px;
    input {
      width: 100%;
      height: 100%;
      outline: 0;
      border: 0;
    }
    .bd {
      border: 2px solid #cccccc;
      border-radius: 10px;
      height: 80px;
      margin-bottom: 20px;
      font-size: 28px;
      padding: 0;
    }
  }
  .btn {
    width: 100%;
    height: 80px;
    display: block;
    background-color: #74b2f8;
    outline: 0;
    border: 0;
    border-radius: 10px;
    margin: 0 auto;
    font-size: 40px;
  }
  .bd::-webkit-input-placeholder {
    color: #aab2bd;
    font-size: 28px;
    padding-left: 10px;
  }
</style>

